package kr.hyunist.androidcomplete01saeildamil.ch12;

import java.util.*;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.content.*;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;

public class MyListAdapter extends BaseAdapter {
	Context maincon;
	LayoutInflater Inflater;
	ArrayList<MyItem> arSrc;
	int layout;

	public MyListAdapter(Context context, int alayout, ArrayList<MyItem> aarSrc) {
		this.maincon = context;
		Inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.arSrc = aarSrc;
		this.layout = alayout;
	}

	@Override
	public int getCount() {
		return arSrc.size();
	}

	@Override
	public String getItem(int position) {
		return arSrc.get(position).Name;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final int pos = position;
		if(convertView == null){
			convertView = Inflater.inflate(layout, parent, false);
		}
		ImageView img = (ImageView) convertView.findViewById(R.id.icontextiv);
		img.setImageResource(arSrc.get(pos).Icon);
		
		TextView tv = (TextView) convertView.findViewById(R.id.icontexttv);
		tv.setText(arSrc.get(pos).Name);
		
		Button b = (Button) convertView.findViewById(R.id.icontextbtn);
		b.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String str = arSrc.get(pos).Name + "을 주문합니다.";
				Toast.makeText(maincon, str, Toast.LENGTH_SHORT).show();
			}
			
		});
		
		return convertView;
	}

}
